<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第四题</title>
</head>

<body>
    <script>
        const goods = [
            { uname: '小米', price: 3000 },
            { uname: '苹果', price: 1000 },
            { uname: '华为', price: 10000 },
            { uname: 'oppo', price: 2000 },
            { uname: 'vivo', price: 2000 },
            { uname: '红米', price: 3000 },
            { uname: '诺基亚', price: 500 },
        ]
        let max = 0, i = 0, sum = 0
        let arr = []
        goods.map(function (item, index) {
            if (item.uname === '小米') {
                console.log(item)
            }
            if (item.price > max) {
                max = item.price
                i = index
            }
            if (item.price >= 3000) {
                arr.push(item)
            }
            sum += item.price
        })
        document.write(`最贵的为：${goods[i].uname},价格为：${goods[i].price}`)
        console.log(arr)
        console.log(`全买价格为:${sum}`)
        let radom = Math.floor(Math.random() * goods.length)
        console.log(goods[radom].uname)
        console.log(goods[radom])
    </script>
</body>

</html>